package de.shb.signature.business;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

import de.shb.signature.dao.SignaturBean;
import de.shb.signature.dao.SignaturManager;
import de.shb.util.presentation.InputPresentationClient;

public class SignaturBusiness implements InputPresentationClient, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5633410443125213220L;
	private static SignaturBusiness inputBusiness = null;

	private SignaturBusiness() {
	}

	SignaturBusinessClient dao = (SignaturBusinessClient) SignaturManager.getInstance();

	public synchronized static InputPresentationClient getInstance() {
		if (inputBusiness == null)
			inputBusiness = new SignaturBusiness();
		return inputBusiness;
	}

	@Override
	public SignaturBean createInput(String commiter, String owner, String comment, String signature) throws SQLException {
		
		SignaturBean input = dao.createSignaturBean();
		input.setComment(comment);
		input.setCommiter(commiter);
		input.setOwner(owner);
		input.setSignature(signature);
		
		input.setAgreed(false);
		input.setDateofcommit(new Date());
		
		dao.save(input);
		return input;
	}

	@Override
	public ArrayList<SignaturBean> findAllInput() throws SQLException {
		SignaturBean[] inputArray = dao.loadAll();
		ArrayList<SignaturBean> inputs = new ArrayList<SignaturBean>();
		for (SignaturBean i : inputArray)
			inputs.add(i);
		return inputs;
	}

}
